﻿using AndoridMoeTool.AndroidTool.SDK.Media;
using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CatImageHelper.UserTool.ImageTool
{
    internal class AddWaterMark
    {
        public static string ImageAddText(string FloderPath)
        {
            List<string> ALLFile = GetAllFile(FloderPath);
            int i = 0;
            foreach (string item in ALLFile)
            {
                Console.WriteLine(item);
                new PrintLog().PercentLog(ALLFile.Count, i++);
                new MagickImageHelper().ImgGray(item, "");
            }

            return "";
        }

        public static List<string> GetAllFile(string FloderPath)
        {
            List<string> FilePathList = new List<string>();

            foreach (var item in GetALLFloder(FloderPath))
            {
                FilePathList.AddRange(FloderNameHelper.GetFullFileNameList(item));
            }

            return FilePathList;
        }

        public static List<string> GetALLFloder(string FloderPath)
        {
            List<string> FloderPathList = new List<string>();
            List<string> TempFloderList = FloderNameHelper.GetFloderNameList(FloderPath);
            if (TempFloderList.Count > 0)
            {
                FloderPathList.AddRange(TempFloderList);
                foreach (var item in TempFloderList)
                {
                    FloderPathList.AddRange(GetALLFloder(item));
                }
            }

            return FloderPathList;
        }

        /// <summary>
        /// 给图片添加文字水印
        /// </summary>
        /// <param name="img">图片
        /// <param name="text">文字
        /// <param name="p">文本位置中心点坐标
        /// <param name="font">字体
        /// <param name="fontColor">字体颜色
        /// <param name="angle">旋转角度（顺时针）
        /// <returns></returns>
        public static Image ImageAddText(Image img, string text, Point p, Font font, Color fontColor, int angle)
        {
            try
            {
                using (var g = Graphics.FromImage(img))
                using (var brush = new SolidBrush(fontColor))
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    var sizeF = g.MeasureString(text, font);
                    g.ResetTransform();
                    g.TranslateTransform(p.X, p.Y);
                    g.RotateTransform(angle);
                    g.DrawString(text, font, brush, new PointF(-sizeF.Width / 2, -sizeF.Height / 2));
                }
                return img;
            }
            catch (Exception ex)
            {
                PrintLog.Log(ex);
            }
            return null;
        }
    }
}